<?php
declare(strict_types=1);
namespace Haozing\Core\Exception;

use Haozing\Core\Constants\ErrorCode;
use Hyperf\Server\Exception\ServerException;
use Throwable;
class CommonException extends ServerException
{
    public function __construct(int $code = 0, string $message = null, Throwable $previous = null)
    {
        if (is_null($message)) {
            $message = ErrorCode::getMessage($code);
            if (! $message && class_exists(\App\Kernel\Constants\ErrorCode::class)) {
                $message = \App\Kernel\Constants\ErrorCode::getMessage($code);
            }
        }

        parent::__construct($message, $code, $previous);
    }
}